package com.hjk.shiny.androidcontrols;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v4.widget.ViewDragHelper;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

/**
 * Created by Maibenben on 2018/2/2.
 */

public class DragViewHelper extends FrameLayout{

    private ViewDragHelper mHelper;

    public DragViewHelper(Context context) {
        this(context,null);
    }

    public DragViewHelper(Context context, @Nullable AttributeSet attrs) {
        this(context,attrs,0);
    }

    public DragViewHelper(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);


        mHelper=ViewDragHelper.create(this, new ViewDragHelper.Callback() {
            @Override
            public boolean tryCaptureView(View child, int pointerId) {
                return true;
            }

            @Override
            public int clampViewPositionHorizontal(View child, int left, int dx) {
                return left;
            }

            @Override
            public int clampViewPositionVertical(View child, int top, int dy) {
                return top;
            }

            @Override
            public void onViewReleased(View releasedChild, float xvel, float yvel) {
                super.onViewReleased(releasedChild, xvel, yvel);
            }
        });
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        mHelper.processTouchEvent(event);

        return true;
    }


    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {



        return mHelper.shouldInterceptTouchEvent(ev);
    }
}
